﻿
@{
    ViewBag.MainMenu = "Member";
    ViewBag.LeftMenu = "GroupMessage";

    ViewBag.Title = "群发功能（已发送)";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script language="javascript">

    //当前页
    var _currentPage = 1;

    $(document).ready(function ()
    {
        loadData();
    });

    function loadData(targetPage)
    {
        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        var args = new Object();
        args.Page = targetPage || 1;

        $.ajax({
            url: "/Api/Member/GetSentGroupMessageList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR)
            {
                // alert(data);

                layer.close(loadLayerIndex);

                if (data.Success)
                {
                    var resultObj = data.Data;

                    _currentPage = resultObj.Page;

                    //alert(JSON.stringify(resultObj));
                    var gettpl = document.getElementById('tableTemplate').innerHTML;
                    laytpl(gettpl).render(resultObj.ItemList, function (html)
                    {
                        document.getElementById('divTableBodyContainer').innerHTML = html;
                        fitTable();
                    });

                    laypage({
                        skin: 'yahei',
                        cont: document.getElementById('divPagingContainer'),
                        pages: resultObj.TotalPage, //总页数
                        curr: resultObj.Page, //当前页
                        groups: 7, //连续显示分页数
                        jump: function (obj, first)
                        {
                            if (!first)
                            { //点击跳页触发函数自身，并传递当前页：obj.curr
                                loadData(obj.curr);
                            }
                        }
                    });

                } else
                {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function scrollHeader()
    {
        // alert(divTableBodyContainer.scrollLeft);
        var ml = 0 - divTableBodyContainer.scrollLeft;
        document.getElementById("tableHeader").style.cssText = "margin-left:" + ml + "px;";
    }

    function fitTable()
    {
        $("#tableBody").width($("#tableHeader").width());

        $("#tableHeader tr:first").each(function (n, value)
        {
            $(this).find("td").each(function (n, value)
            {
                $("#tableBody tr:first td:eq(" + n + ")").width(value.width)
            });
        });
    }

    function showDetail(id)
    {
        layer.open({
            type: 2,
            area: ['660px', '400px'], //宽高
            closeBtn: false,
            title: "",
            shift: _layerShift,
            content: 'GroupMessageDetail?id=' + id
        });
    }

</script>


<script id="tableTemplate" type="text/html">

    <table id="tableBody" border="0" cellspacing="0" cellpadding="0">

        {{# for(var i = 0, len = d.length; i < len; i++){ }}

        @*{{# var submitTime = new Date(d[i].SubmitTime).format("yyyy-MM-dd hh:mm:ss");}}*@

        <tr>
            <td height="35"><a href="javascript:void(0)" onclick="showDetail('{{ d[i].Id }}')">{{ d[i].SubmitTime }}</a></td>
            <td>
                {{# if(d[i].Type == 0){ }}
                文本
                {{# }else if(d[i].Type == 1){ }}
                图片
                {{# }else if(d[i].Type == 2){ }}
                图文
                {{# } }}
            </td>
            <td>{{ d[i].GroupName }}</td>
            <td>
                {{# if(d[i].Status == '' || d[i].Status == null){ }}
                已提交
                {{# }else if(d[i].Status == 'send success'){ }}
                成功
                {{# }else if(d[i].Status == 'send fail'){ }}
                失败
                {{# }else if(d[i].Status == 'err(10001)'){ }}
                涉嫌广告
                {{# }else if(d[i].Status == 'err(20001)'){ }}
                涉嫌政治
                {{# }else if(d[i].Status == 'err(20004)'){ }}
                涉嫌社会 
                {{# }else if(d[i].Status == 'err(20002)'){ }}
                涉嫌色情
                {{# }else if(d[i].Status == 'err(20006)'){ }}
                涉嫌违法犯罪
                {{# }else if(d[i].Status == 'err(20008)'){ }}
                涉嫌欺诈
                {{# }else if(d[i].Status == 'err(20013)'){ }}
                涉嫌版权
                {{# }else if(d[i].Status == 'err(22000)'){ }}
                涉嫌互推(互相宣传) 
                {{# }else if(d[i].Status == 'err(21000)'){ }}
                涉嫌其他
                {{# } }}
            </td>
            <td>{{ d[i].SentCount }}</td>
            <td>{{ d[i].ErrorCount }}</td>
        </tr>
        {{# } }}

    </table>

</script>



<div id="divContentTips">
    配置公众平台账号，才能让你的店铺与微信公众号关联。   <a href="#">查看详细&gt;</a>
</div>

<div style=" margin-top:20px;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="td_ContentTab" style="width:200px;"><a href="/Member/GroupMessage" class="a_black_16">新建群发消息</a></td>
            <td class="td_ContentTab_active" style="width:200px;">已发送</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="4" bgcolor="#EEEEEE" height="2"></td>
        </tr>
    </table>
</div>

<div style=" margin-top:20px">
    <div style="overflow:hidden; padding-left:20px;" class="tableHeader">

        <table id="tableHeader" border="0" cellspacing="0" cellpadding="0" width="1010" height="47">
            <tr>
                <td width="200">提交时间</td>
                <td width="150">消息类型</td>
                <td width="210">发送设置</td>
                <td width="150">发送状态</td>
                <td width="150">成功发送人数</td>
                <td width="150">失败人数</td>
            </tr>
        </table>
    </div>

    <div style=" margin-top:10px">
        <!--div必须要设置height，否则滚动条出不来-->
        <div id="divTableBodyContainer" style="overflow:auto; height:100%;; padding-left:20px;" onscroll="scrollHeader()">
            <!--table必须要有一个确切的宽度，否则无法超出div-->

            
        </div>

    </div>

</div>
<div style="height:1px; margin-top:5px; background-color:#cccccc">

</div>

<div id="divPagingContainer" style=" margin-top:20px; margin-bottom:20px;text-align:right; ">
    paging
</div>
